package com.jxsd.edu.cn.struts2.daoImpl;

import java.util.List;

import com.jxsd.edu.cn.struts2.dao.SmallCatagoryDao;
import com.jxsd.edu.cn.struts2.models.SmallCatagory;
import com.jxsd.edu.cn.tools.ResultBean;
import com.jxsd.edu.cn.tools.ResultList;
import com.jxsd.edu.cn.tools.Template;

public class SmallCatagoryDaoImpl implements SmallCatagoryDao {

	@Override
	public List<SmallCatagory> getAllSmalls(String catagoryId) {
		ResultList<SmallCatagory>  hander=new  ResultList<SmallCatagory>();
		Object[]  params={catagoryId};
		String  sql="select  smallID,SmallName,catagoryID  from  smallcatagory  where  catagoryId=?";
		List<SmallCatagory>  list=null;
		try {
			list=hander.handler(sql, params, SmallCatagory.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}

	@Override
	public SmallCatagory getSmallCatagory(String smallId) {
		ResultBean<SmallCatagory>  hander=new  ResultBean<SmallCatagory>();
		Object[] params={smallId};
		String  sql="select SmallID,SmallName  from  smallcatagory  where smallId=?";
		SmallCatagory  small=null;
		try {
			small=hander.handler(sql, params, SmallCatagory.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return small;
	}

	@Override
	public void addSmallCategory(SmallCatagory small) {
		Template  t=new  Template();
		Object[]  params={small.getSmallID(),small.getSmallName(),small.getCatagoryID()};
		String  sql="insert  into  smallcatagory(SmallID,SmallName,catagoryId)  values(?,?,?)";
		t.update(sql, params);
	}

	@Override
	public void delete(String smallId) {
		Template  t=new  Template();
		Object[]  params={smallId};
		String  sql="delete  from  smallcatagory  where  smallId=?";
		t.update(sql, params);
	}

	@Override
	public List<SmallCatagory> getAllSmalls() 
	{
		ResultList<SmallCatagory>  hander=new  ResultList<SmallCatagory>();
	    String  sql="select  SmallID,SmallName  from  smallcatagory";
	    Object[]  params=null;
	    List<SmallCatagory>  list=null;
		try {
			list=hander.handler(sql, params, SmallCatagory.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}

}
